#version 330 core
out vec4 FragColor;

in vec2 TexCoords;

uniform sampler2D screenTexture;

uniform float exposure;

void main()
{ 
    // 常规
    // FragColor = texture(screenTexture, TexCoords); 

    // 反相
    //FragColor = vec4(vec3(1.0 - texture(screenTexture, TexCoords)), 1.0); 

    // 灰度
    // FragColor = texture(screenTexture, TexCoords);
    // float average = 0.2126 * FragColor.r + 0.7152 * FragColor.g + 0.0722 * FragColor.b;
    // FragColor = vec4(average, average, average, 1.0);

    //HDR simple
    // const float gamma = 2.2;
    // vec3 hdrColor = texture(screenTexture, TexCoords).rgb;

    // // Reinhard色调映射
    // vec3 mapped = hdrColor / (hdrColor + vec3(1.0));
    // // Gamma校正
    // mapped = pow(mapped, vec3(1.0 / gamma));

    // FragColor = vec4(mapped, 1.0);

    //HDR exposure
    const float gamma = 1;
    vec3 hdrColor = texture(screenTexture, TexCoords).rgb;

    // 曝光色调映射
    vec3 mapped = vec3(1.0) - exp(-hdrColor * exposure);
    // Gamma校正 
    mapped = pow(mapped, vec3(1.0 / gamma));

    FragColor = vec4(mapped, 1.0);
}